package cn.fl.repay.service;

import cn.fl.repay.constant.RepayConstant;
import cn.fl.repay.service.impl.LanHaiBankOfflineRepayStrategy;
import cn.fl.repay.service.impl.TrustOfflineRepayStrategy;
import cn.fl.repay.service.impl.YiLianBankOfflineRepayStrategy;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author: leon (lipengd@shiqiao.com)
 * @createDate: 2020/7/2
 * @company: (C) Copyright shiqiao 2020
 * @since: JDK 1.8
 * @description:
 */
@Component
public class OfflineRepayStrategyFactory implements ApplicationContextAware {
    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public OfflineRepayStrategy getRepayDtlStrategy(String insCode){
//        if (StringUtils.isEmpty(insCode)) {
//            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "资管机构不存在.");
//        }
        if (StringUtils.isEmpty(insCode) ||
                insCode.equals(RepayConstant.LOAN_CHANNEL_YNXT) ||
                insCode.equals(RepayConstant.LOAN_CHANNEL_WKXT)) {
            return applicationContext.getBean(TrustOfflineRepayStrategy.class);
        } else if (insCode.equals(RepayConstant.LOAN_CHANNEL_YLYH)){
            return applicationContext.getBean(YiLianBankOfflineRepayStrategy.class);
        } else if (insCode.equals(RepayConstant.LOAN_CHANNEL_LHYH)){
            return applicationContext.getBean(LanHaiBankOfflineRepayStrategy.class);
        }
        return null;
    }
}
